#ifndef __ROM_DEF_H__
#define __ROM_DEF_H__

#include <stdint.h>

#include "sdk_core/rc24xx.h"

#include "udk_support_def/alg_def.h"
#include "udk_support_def/dp_def.h"
#include "udk_support_def/rf_def.h"
#include "udk_support_def/bb_def.h"
#include "udk_support_def/func_def.h"


#define TRUE  (1)
#define FALSE (0)

#define SDK_VERSION_GENE(x,y) (x*64+y)

#define SDK_VERSION (SDK_VERSION_GENE(0,3))
#define SDK_VERSION_APPEND    "2311011500" // 不使用编译时间，sdk内手动填写，确保重复编译生成bin文件一致

/*SRAM*/
#define PARAM_OFFSET_ADDR             (0x2000)
#define PARAM_BASEADDR                (SRAM_BASE+PARAM_OFFSET_ADDR)

#define UDP_ADDR                      (PARAM_BASEADDR)
#define UDP_SIZE                      (sizeof(param_2k_t))

#define FLASH_SECTOR_SIZE             (4*1024)
#define FLASH_PAGE_SIZE               (256)
#define FLASH_PAGE_PER_SECTOR         (16)

#define BBE_SRAM_SIZE                 (40*1024)

#define SYS_ALIGN(x, n) ((x + (n-1)) & ~(n-1))

typedef struct{
	PARAM_ANA_VENUS paramANA;
	PARAM_DATAPREP  paramDataPrep;
	PARAM_ALGORITHM paramALG;
	PARAM_FUNC      paramFunc;
	uint8_t         rsv[216];
}param_2k_t;      // 注: UDF内重新参照此处重新定义为UDP_2K_t

#define SYSBIN_SIZE_MAX (48*1024)

// XIP 0~48K 定义为内部 48K以外定义为外部
// ROM 0~48K 定义为内部 FLASH定义为外部
#define SYSBOOT_UDT_OFFSET_OUTER        (16*1024)  // romboot: 16k  periph-bus ; xipboot 16k+SYSBIN_SIZE_MAX  sys-bus
#define SYSBOOT_UDT_ADDR_INNER          (45*1024)  // 45K @ sys-bus


#define UDT_SRC_INNER  (0)
#define UDT_SRC_OUTER  (1)

#define ROM_STARTUP (0)
#define XIP_STARTUP (1)

#define UDT_MAX_NUM         (17)

#define RAM_USER_START			0x20000000	// move flash Function to Ram region start address 
#define RAM_USER_END			  0x20002800	// move flash Function to Ram region end address

#define FLASH_JUMP_START		0x08000000	// jump flash region valid start address
#define FLASH_JUMP_END			0x20000000	// jump flash region valid end address

#define IRQ_HANDLE_SRAM     (0x20000680)
#define JUMP_IRQ_HANDLE(x)  ((void (*)(int))(IRQ_HANDLE_SRAM+1))(x)

#define GLOBAL_PARAM_ADDR   (0x20000010)

#define UART_REC_MAX_LEN    (50)

typedef struct
{
	/*不可修改 start*/
	struct
	{
	uint8_t RecCount; // 4
	uint32_t RecLen;  // 4
	uint8_t RecFinish;
	uint8_t RecData;
	uint8_t RecBuff[UART_REC_MAX_LEN];
	uint8_t timeoutStart; // 56
	uint32_t timeoutCnt;  // 4
	uint32_t writeCnt;    // 4
	}strUart;            // 老rom启动UDF，不可用

	uint8_t version;     // @0x20000048  // 兼容老rom,老rom可能取0x00,0x01,0x02
	uint8_t WorkMode;    // @0x20000049
	uint8_t boot_flag;   // 老rom启动，不可用
	uint8_t udt_src;     // 老rom启动，不可用

	uint8_t printen;     // 考虑udf兼容性，udf不可用
	uint8_t debug_en;    // 考虑udf兼容性，udf不可用

	uint32_t udp_addr;   // 考虑udf兼容性，udf不可用
	uint32_t SysTick_cnt;// 考虑udf兼容性，udf不可用
	param_2k_t * p_2k;   // 考虑udf兼容性，udf不可用
	float rtcCalibRtnClk;// 考虑udf兼容性，udf不可用
	/*不可修改 end*/
}GLOBAL_PARAM;



typedef struct{
	uint32_t rsv[256];
}SYSRSV_PARAM;

#define OFFSET_SYSRSV (0xBC00)



#define NUM_BYTE8                   (1)
#define NUM_BYTE16                  (2)
#define NUM_BYTE32                  (4)

#define COPY_MODE_32BIT             (2)

#define NUMLOG_2   			            (1)
#define NUMLOG_4   			            (2)
#define NUMLOG_8   			            (3)
#define NUMLOG_16   		            (4)
#define NUMLOG_32   		            (5)
#define NUMLOG_64   		            (6)
#define NUMLOG_128   		            (7)
#define NUMLOG_256   		            (8)
#define NUMLOG_512   		            (9)
#define NUMLOG_1024   	            (10)



#endif
